---@module 用户的orm数据结构

local _usr = class("ModelUser", require("framework.orm.base"))
--======================================
--default params
local d = Ding
local Logger = d.Logger
local uuid = d.uuid
local resty_md5 = require("resty.md5")
local resty_string = require("resty.string")
--======================================
--性别
local SEX_TYPE = {
    male = 1,
    female = 2
}

--角色类型
local ROLE_TYPE = {
    gm = 101,
    normal = 102
}

--登录方式
local LOGIN_TYPE = {
    master = 1,
    admin = 2
}

--错误描述
local ERR_DESC = {
    create_failed = {errcode = 101, errdesc = "create user failed"}
}

local function chk_roletype_validly(roletype)
    Logger:debug("--->>>>roletype = %s", roletype)
    if ROLE_TYPE[roletype] ~= nil then 
        return true 
    end
end

local function encode_pwd(pwd)
    local md5 = resty_md5.new()
    md5:update(pwd)
    local digest = md5:final()
    return string.upper(resty_string.to_hex(digest))
end   

function _usr:ctor(cfg)
    self.super.ctor(self, cfg)
end

function _usr:new_model(username_, pwd_, nickname_, roletype_)
    if not chk_roletype_validly(roletype_) then return end 
    local n_time = ngx.now() * 1000
    local emp_usr = {
        username = username_,
        password = encode_pwd(pwd_), 
        nickname = nickname_,
        roletype = ROLE_TYPE[roletype_],
        lastlogin_time = ngx.now(),
        reg_time = ngx.now()
    }
    Logger:dump(emp_usr,"-->>empuser")
    return emp_usr
end

function _usr:new_insert()
    
end

return _usr
